package innerclass;

public class Sequence2 {
    private String[] str;
    private int next=0;//下标

    Sequence2(int size){
        str=new String[size];
    }
    public void add(String s){
        if (next<str.length)
            str[next++]=s;
    }
    class Sequence2Selector implements Selector{
        int i=0;
        @Override
        public boolean end() {
            return i==str.length;
        }

        @Override
        public Object current() {
            return str[i];
        }

        @Override
        public void next() {
            if (i<str.length)
                i++;
        }
    }
    //------------------------------
    public Selector selector(){
        return new Sequence2Selector();
    }

    public static void main(String[] args) {
        Sequence2 sequence2=new Sequence2(5);
        for (int i = 0; i <5; i++) {
            sequence2.add("abc"+i+" ");
        }
        Selector selector=sequence2.selector();
        while (!selector.end()){
            System.out.print(selector.current());
            selector.next();
        }

    }
}
